<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/css/element.css">
    <script src="/js/vue2.6.js"></script>
    <script src="/js/element.js"></script>
    <script src="/js/axios.js"></script>
    <script src="/js/app.js"></script>
    <title>登入</title>
    <style>
        .el-select .el-input {
            width: 130px;
        }
        .input-with-select .el-input-group__prepend {
            background-color: #fff;
        }
    </style>
</head>
<body style="background-color:#E4E7ED ">
<div id="app" >
    <div align="center" style="padding-top: 200px;">
        <div style="width: 600px;height:270px;background-color:white;border-radius: 6px ">
            <el-form ref="form" :model="form" label-width="80px" style="width: 500px;padding-top: 50px;padding-right: 20px">
                <el-form-item label="账号">
                    <el-input v-model="form.username"></el-input>
                </el-form-item>
                <br>
                <el-form-item label="密码">
                    <el-input type="password" v-model="form.password"></el-input>
                </el-form-item>
                <br>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">登入</el-button>
                    <el-button>取消</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</div>
<script>
    var Main = {
        data() {
            return {
                form: {
                    'username':'',
                    'password':''
                }
            }
        },
        created(){

        },
        methods: {
            onSubmit() {
                if(this.form.username===''||this.form.password===''){
                    this.$message({
                        message: '请输入账号或者密码',
                        type: 'warning'
                    });
                }
                var formData=new FormData();
                formData.append("username",this.form.username)
                formData.append("password",this.form.password)
                api.POSTData('/login',formData,(result)=>{
                    if(result.code==200){
                        localStorage.setItem('token',result.token)
                        location.href='/${html}'
                    }else {
                        this.$message({
                            message: result.message,
                            type: 'warning'
                        });
                    }

                })
                console.log('submit!');
            }
        }
    }
    var Ctor = Vue.extend(Main)
    new Ctor().$mount('#app')
</script>
</body>
</html>